package com.tmc.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.tmc.bean.common.ContextInfo;
import com.tmc.bean.common.Pagination;
import com.tmc.bean.intair.EthShoppingReq;
import com.tmc.entity.intair.BaseCommision;
import com.tmc.util.ObjectUtil;

@Repository
public class BaseCommisionDaoImpl extends BaseDaoImpl<BaseCommision> {

	public List<BaseCommision> findPolicys(ContextInfo context, EthShoppingReq req) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from BaseCommision c where c.enabledFlag = 'Y'");
		
		if (req.getAirline() != null && !"".equals(req.getAirline())) {
			sql.append(" and c.airline = :airline");
			params.put("airline", req.getAirline());
		}
		return this.findList(sql.toString(), params);
	}
	
	public Pagination<BaseCommision> findPolicysByCon(ContextInfo context, BaseCommision cond, int pageIndex, int pageSize) {
		Map<String, Object> params = new HashMap<String, Object>();
		StringBuilder sql = new StringBuilder();
		sql.append(" from BaseCommision c where c.enabledFlag = 'Y' ");
		if (ObjectUtil.hasText(cond.getAirline())) {
			sql.append(" and c.airline = :airline");
			params.put("airline", cond.getAirline());
		}
		sql.append(" order by c.lastUpdateDate desc ");
		return this.findPagination(sql.toString(), params, pageIndex, pageSize);
	}

}
